﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TodoApp.CategoryModel;
using TodoApp.Enum;
using TodoApp.TodoCategorysDTO;
using Volo.Abp.Domain.Repositories;

namespace TodoApp
{
    public class CategorysService : Volo.Abp.Application.Services.ApplicationService, ITodoCategorysService
    {

        /// <summary>
        ///  注入 
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>

        private readonly IRepository<TodoCategorys, Guid> _todoCategorys;
        public CategorysService(IRepository<TodoCategorys, Guid> todoCategorys) {

            _todoCategorys = todoCategorys;
        }

        /// <summary>
        ///   添加  
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
       
        public async Task<ShopStatus> CreateAsync(CategorysAddDTO Model)
        {
            await _todoCategorys.InsertAsync(ObjectMapper.Map<CategorysAddDTO,TodoCategorys>(Model));
            return ShopStatus.Succeed;
        }

        /// <summary>
        ///  删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
       
        public async Task DeleteAsync(Guid id)
        {
            await _todoCategorys.DeleteAsync(id);
        }

        /// <summary>
        /// 显示  
        /// </summary>
        /// <returns></returns>

        public async Task<List<CategorysShowDTO>> GetCategorys()
        {
            var str = await _todoCategorys.GetListAsync();
            return ObjectMapper.Map<List<TodoCategorys>, List<CategorysShowDTO>>(str);
        }

        /// <summary>
        ///  详情 反填 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public async Task<CategorysShowDTO> FindAsync(Guid id)
        {
            var str = await _todoCategorys.FindAsync(id);
            return ObjectMapper.Map<TodoCategorys, CategorysShowDTO>(str);
        }


        /// <summary>
        ///  修改 
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>

        public async Task<ShopStatus> UpdateAsync(CategorysAddDTO Model)
        {
            var str = await _todoCategorys.UpdateAsync(ObjectMapper.Map<CategorysAddDTO,TodoCategorys>(Model));

            return ShopStatus.Succeed;
        }
    }
}
